home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libs / info / signals.c < prev    next >
C/C++ Source or Header  |  1997-08-14  |  6KB  |  191 lines

  1. /* signals.c -- Install and maintain Info signal handlers. */
  2. /* Changed for emx by Kai Uwe Rommel & Eberhard Mattes -- Nov 1995 */
  3. /* Modified by Klaus Gebhardt, 1996 */
  4.  
  5. /* This file is part of GNU Info, a program for reading online documentation
  6.    stored in Info format.
  7.  
  8.    Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  9.  
  10.    This program is free software; you can redistribute it and/or modify
  11.    it under the terms of the GNU General Public License as published by
  12.    the Free Software Foundation; either version 2, or (at your option)
  13.    any later version.
  14.  
  15.    This program is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.    You should have received a copy of the GNU General Public License
  21.    along with this program; if not, write to the Free Software
  22.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23.  
  24.    Written by Brian Fox (bfox@ai.mit.edu). */
  25.  
  26. #include "info.h"
  27. #include "signals.h"
  28.  
  29. /* **************************************************************** */
  30. /*                                    */
  31. /*        Pretending That We Have POSIX Signals            */
  32. /*                                    */
  33. /* **************************************************************** */
  34.  
  35. #if !defined (HAVE_SIGPROCMASK) && defined (HAVE_SIGSETMASK)
  36. /* Perform OPERATION on NEWSET, perhaps leaving information in OLDSET. */
  37. static void
  38. sigprocmask (operation, newset, oldset)
  39.      int operation, *newset, *oldset;
  40. {
  41.   switch (operation)
  42.     {
  43.     case SIG_UNBLOCK:
  44.       sigsetmask (sigblock (0) & ~(*newset));
  45.       break;
  46.  
  47.     case SIG_BLOCK:
  48.       *oldset = sigblock (*newset);
  49.       break;
  50.  
  51.     case SIG_SETMASK:
  52.       sigsetmask (*newset);
  53.       break;
  54.  
  55.     default:
  56.       abort ();
  57.     }
  58. }
  59. #endif /* !HAVE_SIGPROCMASK && HAVE_SIGSETMASK */
  60.  
  61. /* **************************************************************** */
  62. /*                                    */
  63. /*            Signal Handling for Info                */
  64. /*                                    */
  65. /* **************************************************************** */
  66.  
  67. typedef void SigHandlerType;
  68. typedef SigHandlerType SigHandler ();
  69.  
  70. static SigHandlerType info_signal_handler ();
  71. static SigHandler *old_TSTP, *old_TTOU, *old_TTIN;
  72. static SigHandler *old_WINCH, *old_INT, *old_BREAK;
  73.  
  74. void
  75. initialize_info_signal_handler ()
  76. {
  77. #if defined (SIGTSTP)
  78.   old_TSTP = (SigHandler *) signal (SIGTSTP, info_signal_handler);
  79.   old_TTOU = (SigHandler *) signal (SIGTTOU, info_signal_handler);
  80.   old_TTIN = (SigHandler *) signal (SIGTTIN, info_signal_handler);
  81. #endif /* SIGTSTP */
  82.  
  83. #if defined (SIGWINCH)
  84.   old_WINCH = (SigHandler *) signal (SIGWINCH, info_signal_handler);
  85. #endif
  86.  
  87. #if defined (SIGINT)
  88.   old_INT = (SigHandler *) signal (SIGINT, info_signal_handler);
  89. #endif
  90.  
  91. #if defined (SIGBREAK)
  92.   old_BREAK = (SigHandler *) signal (SIGBREAK, info_signal_handler);
  93. #endif
  94. }
  95.  
  96. static void
  97. redisplay_after_signal ()
  98. {
  99.   terminal_clear_screen ();
  100.   display_clear_display (the_display);
  101.   window_mark_chain (windows, W_UpdateWindow);
  102.   display_update_display (windows);
  103.   display_cursor_at_point (active_window);
  104.   fflush (stdout);
  105. }
  106.  
  107. static SigHandlerType
  108. info_signal_handler (sig)
  109.      int sig;
  110. {
  111.   SigHandler **old_signal_handler;
  112.  
  113.   switch (sig)
  114.     {
  115. #if defined (SIGTSTP)
  116.     case SIGTSTP:
  117.     case SIGTTOU:
  118.     case SIGTTIN:
  119. #endif
  120. #if defined (SIGINT)
  121.     case SIGINT:
  122. #endif
  123. #if defined (SIGBREAK)
  124.     case SIGBREAK:
  125. #endif
  126.       {
  127. #if defined (SIGTSTP)
  128.     if (sig == SIGTSTP)
  129.       old_signal_handler = &old_TSTP;
  130.     if (sig == SIGTTOU)
  131.       old_signal_handler = &old_TTOU;
  132.     if (sig == SIGTTIN)
  133.       old_signal_handler = &old_TTIN;
  134. #endif /* SIGTSTP */
  135.     if (sig == SIGINT)
  136.       old_signal_handler = &old_INT;
  137.  
  138.     if (sig == SIGBREAK)
  139.       old_signal_handler = &old_BREAK;
  140.  
  141.     /* For stop signals, restore the terminal IO, leave the cursor
  142.        at the bottom of the window, and stop us. */
  143. #ifdef __EMX__
  144.     terminal_goto_xy (0, screenheight - 2);
  145. #else
  146.     terminal_goto_xy (0, screenheight - 1);
  147. #endif
  148.     terminal_clear_to_eol ();
  149.     fflush (stdout);
  150.     terminal_unprep_terminal ();
  151.     signal (sig, *old_signal_handler);
  152.      UNBLOCK_SIGNAL (sig);
  153.     if (external_info_search_P == 0)
  154.       kill (getpid (), sig);
  155.  
  156.     /* The program is returning now.  Restore our signal handler,
  157.        turn on terminal handling, redraw the screen, and place the
  158.        cursor where it belongs. */
  159.     terminal_prep_terminal ();
  160.     *old_signal_handler = (SigHandler *) signal (sig, info_signal_handler);
  161.     redisplay_after_signal ();
  162.     fflush (stdout);
  163.       }
  164.       break;
  165.  
  166. #if defined (SIGWINCH)
  167.     case SIGWINCH:
  168.       {
  169.     /* Turn off terminal IO, tell our parent that the window has changed,
  170.        then reinitialize the terminal and rebuild our windows. */
  171.     old_signal_handler = &old_WINCH;
  172.     terminal_goto_xy (0, 0);
  173.     fflush (stdout);
  174.     terminal_unprep_terminal ();
  175.     signal (sig, *old_signal_handler);
  176.      UNBLOCK_SIGNAL (sig);
  177.     kill (getpid (), sig);
  178.  
  179.     /* After our old signal handler returns... */
  180.     terminal_get_screen_size ();
  181.     terminal_prep_terminal ();
  182.     display_initialize_display (screenwidth, screenheight);
  183.     window_new_screen_size (screenwidth, screenheight, (VFunction *)NULL);
  184.     *old_signal_handler = (SigHandler *) signal (sig, info_signal_handler);
  185.     redisplay_after_signal ();
  186.       }
  187.       break;
  188. #endif /* SIGWINCH */
  189.     }
  190. }
  191.